<!DOCTYPE html>
<!--
  ~ /*
  ~  (C) Copyright 2016 Ymatou (http://www.ymatou.com/).
  ~  All rights reserved.
  ~  */
  -->

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Blur Admin</title>

  <link href='css/google.css' rel='stylesheet' type='text/css'>

  <link rel="icon" type="image/png" sizes="16x16" href="assets/img/favicon-16x16.png">
  <link rel="icon" type="image/png" sizes="32x32" href="assets/img/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="96x96" href="assets/img/favicon-96x96.png">

  <!-- build:css({.tmp/serve,src}) css/vendor.css -->
  <!-- bower:css -->
  <link rel="stylesheet" href="scripts/blur-admin/bootstrap.css" >

  <link rel="stylesheet" href="scripts/blur-admin/style.css" >
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css({.tmp/serve,src}) css/login.css -->
  <!-- inject:css -->
  <link rel="stylesheet" href="app/auth.css">
  <!-- endinject -->
  <!-- endbuild -->

  <script src="scripts/blur-admin/jquery.js"></script>
  <script type="application/javascript">

    var loginUrl = "/auth";
    var successUrl = "index.html";

    document.onkeydown=function(event){
      if (event.keyCode == 13){
        $("#loginBtn").click();
      }
    };


    function login(){
      var usernameVal = $("#username").val();
      var passwordVal = $("#password").val();
      var message = $("#message");
      if($.trim(usernameVal) != "" && $.trim(passwordVal) != ""){
        $.ajax({
          url: loginUrl,
          data: $.param({
            username: usernameVal,
            password: passwordVal,
          }),
          success: function(data){
            if(data.success){
              window.location = successUrl;
            }else{
              message.text(data.message);
              message.show();
            }
          }
        });
      }else{
        message.text("用户名或密码为空！");
      }
    }
  </script>
</head>
<body>
<main class="auth-main">
  <div class="auth-block">
    <h1>登录</h1>
    <form class="form-horizontal">
      <div class="form-group">
        <label for="username" class="col-sm-2 control-label">用户名</label>

        <div class="col-sm-10">
          <input type="username" class="form-control" id="username" placeholder="用户名">
        </div>
      </div>
      <div class="form-group">
        <label for="password" class="col-sm-2 control-label">密码</label>

        <div class="col-sm-10">
          <input type="password" class="form-control" id="password" placeholder="Password">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <div id="message" style="color: red;display: none"></div>
          <button id="loginBtn" type="button" onclick="login();" class="btn btn-default btn-auth">登录</button>
        </div>
      </div>
    </form>

  </div>
</main>
</body>
</html>